package com.example.security.demo.controller.advice;

import com.example.security.demo.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zhanpengguo
 * @date 2019-07-03 17:37
 */
@Slf4j
@RestControllerAdvice
public class JsonExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Object errorHandler(HttpServletRequest request, HttpServletResponse response, Exception e){
        log.error("系统错误", e);
        return new R(new Throwable(e.getMessage()));
    }
}
